package cz.schovjan.proj.util;

import java.io.UnsupportedEncodingException;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

/**
 * Trida pro praci s retezci.
 * @author schovjan
 *
 */
public class StringUtil {
	
	
	/**
	 * Prevede string enumu na zakodovany enkryptovany retezec.
	 * @param em
	 * @return zakodovany retezec
	 */
	@SuppressWarnings("restriction")
	public static String toSecretString(String err) {
		try {
			return Base64.encode(err.toString().getBytes("UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		return err.toString();
	}
	
	
	/**
	 * String dekryptuje a dekoduje a vraci jej ve Stringu.
	 * @param s
	 * @return dekryptovany a dekodovany retezec
	 */
	@SuppressWarnings("restriction")
	public static String fromSecretString(String s) {
		try {
			return new String (Base64.decode(s), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		return s;
	}
	
}
